package org.xuyuji.test.jettydemo.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.xuyuji.test.jettydemo.servlet.HelloServlet;

public class ResourceServer {
	public void start(int port) throws Exception{
		Server server = new Server(port);

		ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
		servletHandler.setContextPath("/apple");
		servletHandler.addServlet(new ServletHolder(new HelloServlet()), "/hello.do");
		
		ResourceHandler resourceHandler = new ResourceHandler();
		//首页设置，有默认值，index.html是其中之一
		resourceHandler.setWelcomeFiles(new String[] { "index.html" });
		resourceHandler.setResourceBase("web");
		resourceHandler.setDirectoriesListed(true);//可以访问文件目录
		resourceHandler.setHandler(servletHandler);

		server.setHandler(resourceHandler);
		server.start();
		server.join();
	}
}
